#ifndef _MAIN_LOGGER_H
#define _MAIN_LOGGER_H

#include <Ogre.h>
#include <time.h>
#include <list>
#include <string>

//tolua_begin
namespace Main
{
//tolua_end
	class Logger;

	class LogListener
	{
		friend class Logger;
	protected:
		virtual void receiveLogMessage(const std::string message,time_t timestamp,const std::string source) =0;
	};

	

	class Logger //tolua_export
		: public Ogre::Singleton<Logger>
	{			//tolua_export

		static size_t QueueLength;

		struct LogMessage
		{
			std::string message;
			time_t timestamp;
			std::string source;
			LogMessage(std::string &_message,std::string &_source)
			{
				message = _message;
				time(&timestamp);
				source = _source;
			}
		};
		
		std::list<LogMessage> mMessages;
		std::list<LogListener*> mListeners;
	public:
		~Logger();
//tolua_begin
		static Logger &getSingleton();
		void logMessage(std::string &message,std::string &source);
//tolua_end
		void registerListener(LogListener *listener,bool includeHistory = false);
		void deregisterListener(LogListener *listener);
	}; // tolua_export

	class Loggable
	{
	protected:
		std::string mSource;
		Loggable(std::string source)
				:mSource(source)
		{}
		void logMessage(std::string message)
		{
			Logger::getSingleton().logMessage(message,mSource);	
		}
	};

	class FileLogListener :public LogListener
	{
		std::string mFileName;
	public:
		FileLogListener(std::string fileName);
	protected:
		virtual void receiveLogMessage(const std::string message,time_t timestamp,const std::string source);


	};

//tolua_begin
};
//tolua_end

#endif